/* GUI CONVERTED from reschdel.p (converter v1.75) Fri Jun 22 15:25:43 2001 */
/* reschdel.p - REPETITIVE SCHEDULE DELETE                                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.16 $                                                           */
/*F0PN*/ /*V8:ConvertMode=Report                                              */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94 BY: WUG *GN77*                  */
/* REVISION: 7.3      LAST MODIFIED: 11/03/94 BY: WUG *GN98*                  */
/* REVISION: 7.3      LAST MODIFIED: 04/26/96 BY: jym *G1PZ*                  */
/* REVISION: 8.5      LAST MODIFIED: 06/18/96 BY: taf *J0V0*                  */
/* REVISION: 8.5      LAST MODIFIED: 06/25/96 BY: *G1YN* Julie Milligan       */
/* REVISION: 7.4      LAST MODIFIED: 02/05/98 BY: *H1JC* Jean Miller          */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98 BY: *L007* A. Rahane            */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98 BY: *K1Q4* Alfred Tan           */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98 BY: *J314* Alfred Tan           */
/* REVISION: 9.0      LAST MODIFIED: 02/06/99 BY: *M06R* Doug Norton          */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99 BY: *M0BD* Alfred Tan           */
/* REVISION: 9.1      LAST MODIFIED: 08/19/99 BY: *N01B* John Corda           */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane     */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb                  */
/* $Revision: 1.16 $    BY: Hualin Zhong   DATE: 06/13/01 ECO: *N0ZF*          */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reschdel_p_1 "Qty Open"
/* MaxLen: Comment: */

&SCOPED-DEFINE reschdel_p_2 "Update"
/* MaxLen: 9 Comment: FACILITATE SIMULATION MODE PRINTING */

&SCOPED-DEFINE reschdel_p_3 "Due Dates Before"
/* MaxLen: Comment: */

&SCOPED-DEFINE reschdel_p_4 "Description!BOM Code"
/* MaxLen: Comment: */

&SCOPED-DEFINE reschdel_p_5 "Item Number!Routing Code"
/* MaxLen: Comment: */

&SCOPED-DEFINE reschdel_p_6 "Include Open"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

&SCOPED-DEFINE simulation true
/* PREPROCESSOR USED FOR REPORT'S WITH SIMULATION OPTION */

define variable part  like wo_part no-undo.
define variable part1 like wo_part label {t001.i} no-undo.
define variable site  like wo_site no-undo.
define variable site1 like wo_site label {t001.i} no-undo.
define variable line  like wo_line no-undo.
define variable line1 like wo_line label {t001.i} no-undo.
define variable before_date as date label {&reschdel_p_3} no-undo.
define variable include_open like mfc_logical
   label {&reschdel_p_6} initial yes no-undo.

/* DEFAULT VALUE FOR update_yn IS CHANGED FROM YES TO NO, SINCE */
/* IT IS RECOMMENDED APPROACH IN HELP DOCUMENTATION.            */

define variable update_yn like mfc_logical
   label {&reschdel_p_2} initial no no-undo.

define variable qty_open like rps_qty_comp label {&reschdel_p_1} no-undo.
define variable rpsnbr as character no-undo.
define variable key2   as character no-undo.
define variable r_part as character no-undo.
define variable r_site as character no-undo.
define variable r_line as character no-undo.
define buffer rpsmstr for rps_mstr.
define new shared variable wo_recno as recid.
define new shared variable prev_status like wo_status.
define new shared variable prev_qty like wo_qty_ord.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
part          colon 20
   part1         colon 45
   site          colon 20
   site1         colon 45
   line          colon 20
   line1         colon 45
   skip(1)
   before_date   colon 33
   include_open  colon 33
   update_yn     colon 33
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

find mfc_ctrl where mfc_field = "rpc_using_new" no-lock no-error.
if not available mfc_ctrl or mfc_logical = false then do:

   /*MODULE HAS NOT BEEN ENABLED */
   {pxmsg.i &MSGNUM=5119 &ERRORLEVEL=3}
   message.
   message.
   leave.
end.

/*GET MONDAY OF THIS WEEK*/
{gprun.i ""rswmd.p"" "(input today, input yes, output before_date)"}

repeat:
   if part1 = hi_char then
      part1 = "".
   if site1 = hi_char then
      site1 = "".
   if line1 = hi_char then
      line1 = "".

   update
      part
      part1
      site
      site1
      line
      line1
      before_date
      include_open
      update_yn
   with frame a.

   bcdparm = "".

   {gprun.i ""gpquote.p"" "(input-output bcdparm,9,
                            part,
                            part1,
                            site,
                            site1,
                            line,
                            line1,
                            string(before_date),
                            string(include_open),
                            string(update_yn),
                            null_char,
                            null_char,
                            null_char,
                            null_char,
                            null_char,
                            null_char,
                            null_char,
                            null_char,
                            null_char,
                            null_char,
                            null_char)"}

   if part1 = "" then
      part1 = hi_char.
   if site1 = "" then
      site1 = hi_char.
   if line1 = "" then
      line1 = hi_char.

   /* CHECK SITE ACCESS IF NOT BATCHRUN */
   if not batchrun then do:
      {gprun.i ""gpsirvr.p"" "(input  site,
                               input  site1,
                               output return_int)"}
      if return_int = 0 then do:
         next-prompt site with frame a.
         undo, retry.
      end.
   end.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.

   {mfphead.i}

   for each rps_mstr no-lock
   where rps_part >= part and rps_part <= part1
     and rps_site >= site and rps_site <= site1
     and rps_line >= line and rps_line <= line1
     and rps_due_date < before_date
     and (include_open or rps_qty_req = rps_qty_comp)
   use-index rps_part with frame f_rps:

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame f_rps:handle).

      FORM /*GUI*/ 
         rps_part column-label {&reschdel_p_5}
         pt_desc1 column-label {&reschdel_p_4}
         header
         skip(2)
      with STREAM-IO /*GUI*/  width 132 no-box.

      find pt_mstr where pt_part = rps_part no-lock.

      qty_open = rps_qty_req - rps_qty_comp.

      display
         rps_part
         pt_desc1
         rps_site
         rps_line
         rps_rel_date
         rps_due_date
         rps_qty_req
         rps_qty_comp
         qty_open WITH STREAM-IO /*GUI*/ .

      if rps_routing > "" or rps_bom_code > "" then do:

         down 1.

         display
            rps_routing @ rps_part
            rps_bom_code @ pt_desc1 WITH STREAM-IO /*GUI*/ .
      end.

      if update_yn then do for rpsmstr transaction:

         find rpsmstr where recid(rpsmstr) = recid(rps_mstr)
            exclusive-lock.

         /*CANCEL MRP SUPPLY AND SCRAP*/
         {dateconv.i rps_due_date rpsnbr}
         rpsnbr = rpsnbr + rps_site.
         {mfmrwdel.i "rps_mstr" rps_part rpsnbr string(rps_record) """"}
         {mfmrwdel.i "rps_scrap" rps_part rpsnbr string(rps_record) """"}

         /*DELETE WORK ORDER IF THERE IS ONE*/
         find wo_mstr
         where wo_lot = string(rps_record)
           and wo_part = rps_part
           and wo_type = "S"
           and wo_status = "E"
           and wo_site = rps_site
           and wo_line = rps_line no-lock no-error.

         if available wo_mstr then do:
            assign
               wo_recno    = recid(wo_mstr)
               prev_status = wo_status
               prev_qty    = wo_qty_ord.
            {gprun.i ""wowomtd.p""}
         end.

         assign
            r_part = rps_part
            r_site = rps_site
            r_line = rps_line.

         delete rpsmstr.

         /*IF NO MORE SCHEDULE THEN PURGE QAD_WKFL*/
         find first rpsmstr
         where rps_part = r_part
           and rps_site = r_site
           and rps_line = r_line no-lock no-error.

         if not available rpsmstr then do:
            key2 = r_part + "/" + r_site + "/" + r_line + "/".

            for each qad_wkfl exclusive-lock
            where qad_key1 = "rps_mstr"
              and qad_key2 begins key2:
               delete qad_wkfl.
            end.
         end.

      end. /* if update */

   end. /* for each rps_mstr */

   {mfrtrail.i}

end. /* repeat */
